﻿<!DOCTYPE html>

<html>

<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
</head>

<body>
    <div class="framecontainer">
        <div class="leftcontinaer">
            <div class="cloud-panel">
                <div class="cloud-panel-header ">
                    <div class="cloud-panel-title">部门列表</div>
                </div>
                <div class="cloud-panel-body">
                    <ul id="tree" class="ztree" overflow:auto;"></ul>
                </div>
            </div>
        </div>
        <div class="rightcontinaer">
            <div class="cloud-panel">
                <div class="cloud-panel-header ">
                    <div class="cloud-panel-title">人员管理</div>
                </div>
                <div class="cloud-panel-body">
                    <div class="searchop">
                        <div class="btnop">
                            <button class="btn btn-op" type="button" onclick="SaveRoleSetting()"><span class="btntext">保存设置</span></button>
                        </div>
                        <div class="btnop">
                            <input id="UserName" type="text" class="form-control searchinput" placeholder="请输入人员名称">
                            <div class="checkbox-primary" style="margin-top:5px;margin-left:5px;margin-right:10px"><input type="checkbox" id="SearchInAll"><label for="SearchInAll">所有人员</label></div>
                            <button class="btn" type="button" onclick="BindGrid()"><i class="icon icon-search"></i><span class="searchtext">搜索</span></button>
                        </div>
                    </div>
                    <div class="tableop">
                        <table class="GridStyle" id="CloudGrid" keyid="UserGuid" url="oplist" relationpageid="cloudpagination" otherparm="SearchParm" afterbind="AfterBindData">
                            <tr class="HeaderStyle" id="HeadContainer">
                            </tr>
                        </table>
                    </div>
                    <div class="bottomop">
                        <div class="pageop">
                            <ul class="pagination" id="cloudpagination"></ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var OUGuid = "Top";
        var RoleList;
        $(function () {
            RefreshPage();
            $("#SearchInAll").change(function () {
                BindGrid();
            })
        })
        function BindGrid() {
            var Head = "";
            Head += " <th scope='col' style='width: 10px;' field='index' rowalign='center'>序</th>";
            Head += " <th scope='col'  id='DisplayName' field='DisplayName' rowalign='left' width='100px'>姓名</th>";
            CloudPost({}, getRootPath() + "frame/org/role/oplistall", function (res) {
                RoleList = res.data;
                $(res.data).each(function (index, item) {
                    if (index <= 8) {
                        Head += "  <th scope='col' field='function' functionname='GetRoleCheck' rowalign='center' RoleGuid='" + item.RoleGuid + "'>" + item.RoleName + "</th>"
                    }

                })
                Head += " <th scope='col'  style='width: 50px;' field='SortNum' rowalign='center'>排序</th>";
                Head += " <th scope='col' style='width: 50px;' field='EditButton' functionname='GridEdit' rowalign='center'>设置</th>";
                $("#HeadContainer").html(Head);
                BindCloudGrid($("#CloudGrid"));
            })

        }
        function BindTree() {
            CloudPost({}, getRootPath() + "frame/org/ou/tree", function (res) {
                BindMenuTree("tree", res.data, TreeNodeOnClick);
            })
        }
        function SearchParm() {
            return {
                "UserName": $("#UserName").val(),
                "OUGuid": OUGuid,
                "SearchInAll": $('#SearchInAll').is(':checked')
            };
        }
        function AfterBindData() {

        }
        function GridEdit(RowData) {
            OpenTopDialog("编辑", "frame/org/userrole/edit?userguid=" + RowData.UserGuid, 600, 1000, RefreshPage)
        }
        function RefreshPage() {
            BindGrid();
            BindTree();
        }
        function TreeNodeOnClick(event, treeId, treeNode, clickFlag) {
            OUGuid = treeNode.id
            BindGrid();
        }
        function GetRoleCheck(RowData, tr, RowIndex, ColumnIndex) {
            var Role = RoleList[ColumnIndex - 2]
            if (RowData.RoleGuidList.indexOf(Role.RoleGuid) > -1) {
                return "<input type='checkbox' class='RoleCheckBox' checked UserGuid='" + RowData.UserGuid + "' RoleGuid='" + Role.RoleGuid + "'>";
            } else {
                return "<input type='checkbox' class='RoleCheckBox' UserGuid='" + RowData.UserGuid + "' RoleGuid='" + Role.RoleGuid + "'>";
            }
        }
        function SaveRoleSetting() {
            var Result = [];
            $(".RoleCheckBox").each(function () {
                if ($(this).prop('checked')) {
                    Result.push({ "UserGuid": $(this).attr("UserGuid"), "RoleGuid": $(this).attr("RoleGuid") ,"IsCheck":true});
                } else {
                      Result.push({ "UserGuid": $(this).attr("UserGuid"), "RoleGuid": $(this).attr("RoleGuid") ,"IsCheck":false});
                }
            })
            CloudPost({ "UserRoleRelationStr": JSON.stringify(Result) }, getRootPath() + "frame/org/userrole/batchUpdateUserRole", function (res) {
                if (res.code == 0) {
                    OpenSuccess("保存成功", BindGrid)
                }
            })
        }
    </script>
</body>
</html>